let fs = require("fs");
let path = require('path');
let data = '';

// 创建可读流
filePath = path.resolve(__dirname, 'input.txt')
let readerStream = fs.createReadStream(filePath, {flags:'r', encoding:"utf-8"});

// 设置编码为 utf8。
readerStream.setEncoding('UTF8');

// 处理流事件 --> data, end, and error

readerStream.on('open', function (err) {
    console.log("文件已打开");
});


readerStream.on('data', function (chunk) {
    console.log("单批数据流入" + chunk.length)
    console.log(chunk)
    data += chunk;
});

readerStream.on('end', function () {
    console.log("on end");
});

readerStream.on('error', function (err) {
    console.log(err.stack);
});


readerStream.on("close", function(){
    console.log("on close")
})

console.log("程序执行完毕");